package org.study.plus.boot.vo;

import lombok.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 作用描述
 *
 * @author doveylovey
 * @version v1.0.0
 * @email 1135782208@qq.com
 * @date 2025年08月15日
 */
@Data
public class DynamicSqlRequest {
    /**
     * 表名
     */
    private String table;

    /**
     * 查询列（支持别名，如 ["id", "name", "count(*) as cnt"]
     */
    private List<String> columnList = List.of("*");

    /**
     * 过滤条件
     */
    private List<Filter> filterList = new ArrayList<>();

    /**
     * 排序
     */
    private List<OrderBy> orderByList = new ArrayList<>();

    /**
     * 分组字段
     */
    private List<String> groupByList = new ArrayList<>();

    /**
     * 分组后过滤条件
     */
    private List<Filter> havingList = new ArrayList<>();

    /**
     * 分页
     */
    private PageParam pageParam = new PageParam(1, 10);

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class Filter {
        private String field;   // 字段名
        private Op op;          // 操作符枚举
        private Object value;   // 值（对IN、BETWEEN可以是List、数组）
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class OrderBy {
        private String field;
        private Direction direction; // ASC、DESC
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class PageParam {
        private long current;
        private long size;
    }

    public enum Op {
        EQ, NE, GT, GE, LT, LE, LIKE, LLIKE, RLIKE, IN, BETWEEN, IS_NULL, NOT_NULL
    }

    public enum Direction {
        ASC, DESC
    }
}
